<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- 返回两个日期之间相差的天数 -->
</head>
<body>
  <script>
    /**
 * @param startDate  开始日期 yyyy-MM-dd
 * @param enDate  结束日期 yyyy-MM-dd
 * @returns {number} 两日期相差的天数
 */
  function getDaysBetween(startDate, enDate) {
    let sDate = Date.parse(startDate)
    let eDate = Date.parse(enDate)
    if (sDate > eDate) {
      return 0
    }
    // 这个判断可以根据需求来确定是否需要加上
    if (sDate === eDate) {
      return 1
    }
    let days = (eDate - sDate) / (1 * 24 * 60 * 60 * 1000)
    return days
  }
  let d1 = '2023-04-01'
  let d2 = '2023-04-05'
  let days = getDaysBetween(d1, d2)
  console.log(days)
  </script>
</body>
</html>